package com.example.financechain.controller;

import com.example.financechain.Utils.JsonData;
import com.example.financechain.Utils.AliossUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("private/upload")
public class UploadController {

    @Autowired
    AliossUtils aliossUtils;

    /**
     * 上传文件
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping
    public JsonData upload(MultipartFile file) throws Exception {
        String url = aliossUtils.upload(file);
        if(url==null){
            return JsonData.buildError(20001,"上传失败");
        }else {
            return JsonData.buildSuccess(url);
        }

    }
}
